jQuery(document).ready(function($) {
  $(document).foundation();
});
//foundation初始化
jQuery(document).ready(function($) {
  $(window).on('load', function(event) {
    event.preventDefault();
    var $audio = document.querySelectorAll('.p-audio');
    var $cover = document.querySelectorAll('.cover');
    var playerFun = (function() {
      var audios = Array(),
      names = Array(),
      covers = Array();
      audios[0] = '/audio/Kelly Clarkson - Catch My Breath.mp3';
      names[0] = 'Catch My Breath';
      covers[0] = 'http://p4.music.126.net/8rCjkqlIXl5-HjRQPIqrJg==/2510185046278292.jpg?param=130y130';
      if (covers.length > 0) {
        coverLoad();
        audioLoad();
      }
      function coverLoad() {
        coverSrc = covers[0];
        if ($cover.length) {
          $cover[0].setAttribute('src', coverSrc);
        }
      }
      function audioLoad() {
        if ($audio.length) {
          $audio[0].src = audios[0];
          $audio[0].autoplay = false;
        }
      }
      var updataTime = $audio[0].currentTime,
      allTime = $audio[0].duration;
      var allTimeNow = function() {
        if (isNaN(allTime)) {
          setTimeout(function () {
            audioPlay.controls.duration = $audio[0].duration;
          }, 500);
        }else {
          audioPlay.controls.duration = $audio[0].duration;
          i--;
          return i;
        }
      }
      var allTimeUp = allTimeNow();
      function audioPlay() {
          var datas = {
            name: names[0],
            duration: allTimeUp,
            currentTime: updataTime,
            ended: $audio[0].ended,
          }
          console.log(datas.currentTime);
          var controls = new Vue({
            el: '.player',
            data: datas,
          });
          console.log(controls.duration);
      }
      function fn2() {
        for (var i = 0; i < 10; i++) {
            var tc = setTimeout(function(i) {
                console.log(i);
                // clearInterval(tc)
            }, i*1000, i);
        }
      }
      fn2();
      audioPlay();
    })();
  });
});
